package org.edu.modules.sxjy.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.modules.sxjy.common.noresubmit.CacheLock;
import org.edu.modules.sxjy.entity.VeScoreConfig;
import org.edu.modules.sxjy.service.CacheKeyGenerator;
import org.edu.modules.sxjy.service.IVeScoreConfigService;
import org.edu.modules.sxjy.service.impl.CacheKeyGeneratorImp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags={"实习成绩设置"})
@RestController
@RequestMapping({"/sxjy/veScoreConfig"})
@ApiSort(60)
public class VeScoreConfigController
        extends BaseController<VeScoreConfig, IVeScoreConfigService>
{
    private static final Logger log = LoggerFactory.getLogger(VeScoreConfigController.class);
    @Autowired
    private IVeScoreConfigService veScoreConfigService;

    @Bean
    public CacheKeyGenerator cacheKeyGenerator()
    {
        return new CacheKeyGeneratorImp();
    }

    @AutoLog("实习成绩设置-查询列表")
    @ApiOperation(value="查询列表", notes="实习成绩设置-查询列表")
    @GetMapping({"/selectAll"})
    public Result<?> selectAll(VeScoreConfig veScoreConfig, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize)
    {
        Integer startLine = Integer.valueOf((pageNo.intValue() - 1) * pageSize.intValue());
        List<VeScoreConfig> veScoreConfigList = this.veScoreConfigService.selectAll(veScoreConfig, startLine, pageSize);
        if ((Objects.isNull(veScoreConfigList)) && (veScoreConfigList.size() <= 0)) {
            return Result.OK("未找到对应数据");
        }
        return Result.OK(veScoreConfigList);
    }

    @AutoLog("实习成绩设置-企业教师成绩比例")
    @ApiOperation(value="企业教师成绩比例", notes="实习成绩设置-企业教师成绩比例")
    @GetMapping({"/getCteacherProportion"})
    public Result<?> getCteacherProportion()
    {
        List<VeScoreConfig> veScoreConfigList = this.veScoreConfigService.list();
        Iterator localIterator = veScoreConfigList.iterator();
        if (localIterator.hasNext())
        {
            VeScoreConfig veScoreConfig = (VeScoreConfig)localIterator.next();
            return Result.OK(Integer.valueOf(veScoreConfig.getCteacherProportion()));
        }
        return Result.error("失败");
    }

    @AutoLog("实习成绩设置-学校教师成绩比例")
    @ApiOperation(value="学校教师成绩比例", notes="实习成绩设置-学校教师成绩比例")
    @GetMapping({"/getSteacherProportion"})
    public Result<?> getSteacherProportion()
    {
        List<VeScoreConfig> veScoreConfigList = this.veScoreConfigService.list();
        Iterator localIterator = veScoreConfigList.iterator();
        if (localIterator.hasNext())
        {
            VeScoreConfig veScoreConfig = (VeScoreConfig)localIterator.next();
            return Result.OK(Integer.valueOf(veScoreConfig.getSteacherProportion()));
        }
        return Result.error("失败");
    }

    @AutoLog("实习成绩设置-修改信息")
    @ApiOperation(value="修改信息", notes="实习成绩设置-修改信息")
    @PutMapping({"/edit"})
    @CacheLock(prefix="redisLock.test", expire=1)
    public Result<?> edit(@RequestBody VeScoreConfig veScoreConfig)
    {
        if (veScoreConfig != null)
        {
            veScoreConfig.setTerminalId(1);
            this.veScoreConfigService.updateById(veScoreConfig);
            return Result.OK("编辑成功!");
        }
        return Result.error("失败");
    }
}
